package utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Paginate<T> {
	public int limit;
	List<T> elements;
	
	public Paginate() {
		this.limit = Integer.MAX_VALUE;
		this.elements = null;
	}
	
	public Paginate(int limit) {
		this();
		this.limit = limit;
	}
	
	public Paginate(Collection<T> elements, int limit) {
		this(limit);
		this.elements = new ArrayList<T>(elements);
	}
	
	public List<T> getPage(int page) {
		int current = limit*(page-1);
		int end = limit*page < elements.size() ? limit*page : elements.size();
		current = current >= end ? end : current;
		
		return elements.subList(current, end);
	}
}
